package com.wwe.kotlinstudy

import android.app.Activity
import android.support.annotation.IdRes
import android.view.View


/**
 * @name KotlinStudy
 * @package name：com.wwe.kotlinstudy
 * @anthor DavidZhang
 * @time 2018/6/2 11:17
 * @class describe
 */

fun <T> MutableList<T>?.swap(index1: Int, index2: Int) {
    /*if (this == null) {
        println(null)
        return
    }*/

    this ?: return

    val tmp = this[index1]
    this[index1] = this[index2]
    this[index2] = tmp
}

//How to use
fun use(){
    val list = mutableListOf(1,2,3)
    list.swap(1,2)
}

fun <T : View> Activity.find(@IdRes id: Int): T {
    return findViewById(id) as T
}

//How to use
//var label = find(R.id.label) =》 TextView label = find(R.id.label);

//下面的代码必须定义在Activity
/*
fun Int.onClick(click: ()->Unit){
    val tmp = find<View>(this).apply {
        setOnClickListener{
            click()
        }
    }
}*/

//R.id.label.onClick { Log.d("Glen","onClick TextView") }





























































































